import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { VideoCategoryEntity } from '../../entity/category';
import { VideoCategoryService } from '../../service/category';

/**
 * 视频分类
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: VideoCategoryEntity,
  service: VideoCategoryService,
  pageQueryOp: {
    keyWordLikeFields: ['a.name'],
    fieldEq: ['a.status'],
    where: async ctx => {
      const { minOrder, maxOrder } = ctx.request.body;
      const where = [];
      if (minOrder !== undefined) {
        where.push(['a.order >= :minOrder', { minOrder }]);
      }
      if (maxOrder !== undefined) {
        where.push(['a.order <= :maxOrder', { maxOrder }]);
      }
      return where;
    },
  },
})
export class AdminVideoCategoryController extends BaseController {
  @Inject()
  videoCategoryService: VideoCategoryService;
}
